/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package elaborate.vwbe.dom;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.EntityReference;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
import org.w3c.dom.UserDataHandler;
import org.xml.sax.InputSource;

/**
 * wrapper of original Document implementation
 * to provide some extesion:
 * 1. Xerces does not support html-style getElementById, the wrapper provides that through xpath query
 * @author lendle
 */
public class DocumentEX implements Document{
    private Document delegateDocument=null;

    public Document getDelegateDocument() {
        return delegateDocument;
    }
    
    public DocumentEX(Document delegateDocument) {
        this.delegateDocument=delegateDocument;
    }
    
    public DocumentType getDoctype() {
        return delegateDocument.getDoctype();
    }

    public DOMImplementation getImplementation() {
        return delegateDocument.getImplementation();
    }

    public Element getDocumentElement() {
        return delegateDocument.getDocumentElement();
    }

    public Element createElement(String string) throws DOMException {
        return delegateDocument.createElement(string);
    }

    public DocumentFragment createDocumentFragment() {
        return delegateDocument.createDocumentFragment();
    }

    public Text createTextNode(String string) {
        return delegateDocument.createTextNode(string);
    }

    public Comment createComment(String string) {
        return delegateDocument.createComment(string);
    }

    public CDATASection createCDATASection(String string) throws DOMException {
        return delegateDocument.createCDATASection(string);
    }

    public ProcessingInstruction createProcessingInstruction(String string, String string1) throws DOMException {
        return delegateDocument.createProcessingInstruction(string, string1);
    }

    public Attr createAttribute(String string) throws DOMException {
        return delegateDocument.createAttribute(string);
    }

    public EntityReference createEntityReference(String string) throws DOMException {
        return delegateDocument.createEntityReference(string);
    }

    public NodeList getElementsByTagName(String string) {
        return delegateDocument.getElementsByTagName(string);
    }

    public Node importNode(Node node, boolean bln) throws DOMException {
        return delegateDocument.importNode(node, bln);
    }

    public Element createElementNS(String string, String string1) throws DOMException {
        return delegateDocument.createElementNS(string, string1);
    }

    public Attr createAttributeNS(String string, String string1) throws DOMException {
        return delegateDocument.createAttributeNS(string, string1);
    }

    public NodeList getElementsByTagNameNS(String string, String string1) {
        return delegateDocument.getElementsByTagNameNS(string, string1);
    }

    public Element getElementById(String string) {
        try {
            XPath xpath=XPathFactory.newInstance().newXPath();
            return (Element) xpath.evaluate("//*[@id='"+string+"']", this.delegateDocument, XPathConstants.NODE);
        } catch (XPathExpressionException ex) {
            Logger.getLogger(DocumentEX.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public String getInputEncoding() {
        return delegateDocument.getInputEncoding();
    }

    public String getXmlEncoding() {
        return delegateDocument.getXmlEncoding();
    }

    public boolean getXmlStandalone() {
        return delegateDocument.getXmlStandalone();
    }

    public void setXmlStandalone(boolean bln) throws DOMException {
        delegateDocument.setXmlStandalone(bln);
    }

    public String getXmlVersion() {
        return delegateDocument.getXmlVersion();
    }

    public void setXmlVersion(String string) throws DOMException {
        delegateDocument.setXmlVersion(string);
    }

    public boolean getStrictErrorChecking() {
        return delegateDocument.getStrictErrorChecking();
    }

    public void setStrictErrorChecking(boolean bln) {
        delegateDocument.setStrictErrorChecking(bln);
    }

    public String getDocumentURI() {
        return delegateDocument.getDocumentURI();
    }

    public void setDocumentURI(String string) {
        delegateDocument.setDocumentURI(string);
    }

    public Node adoptNode(Node node) throws DOMException {
        return delegateDocument.adoptNode(node);
    }

    public DOMConfiguration getDomConfig() {
        return delegateDocument.getDomConfig();
    }

    public void normalizeDocument() {
        delegateDocument.normalizeDocument();
    }

    public Node renameNode(Node node, String string, String string1) throws DOMException {
        return delegateDocument.renameNode(node, string, string1);
    }

    public String getNodeName() {
        return delegateDocument.getNodeName();
    }

    public String getNodeValue() throws DOMException {
        return delegateDocument.getNodeValue();
    }

    public void setNodeValue(String string) throws DOMException {
        delegateDocument.setNodeValue(string);
    }

    public short getNodeType() {
        return delegateDocument.getNodeType();
    }

    public Node getParentNode() {
        return delegateDocument.getParentNode();
    }

    public NodeList getChildNodes() {
        return delegateDocument.getChildNodes();
    }

    public Node getFirstChild() {
        return delegateDocument.getFirstChild();
    }

    public Node getLastChild() {
        return delegateDocument.getLastChild();
    }

    public Node getPreviousSibling() {
        return delegateDocument.getPreviousSibling();
    }

    public Node getNextSibling() {
        return delegateDocument.getNextSibling();
    }

    public NamedNodeMap getAttributes() {
        return delegateDocument.getAttributes();
    }

    public Document getOwnerDocument() {
        return delegateDocument.getOwnerDocument();
    }

    public Node insertBefore(Node node, Node node1) throws DOMException {
        return delegateDocument.insertBefore(node, node1);
    }

    public Node replaceChild(Node node, Node node1) throws DOMException {
        return delegateDocument.replaceChild(node, node1);
    }

    public Node removeChild(Node node) throws DOMException {
        return delegateDocument.removeChild(node);
    }

    public Node appendChild(Node node) throws DOMException {
        return delegateDocument.appendChild(node);
    }

    public boolean hasChildNodes() {
        return delegateDocument.hasChildNodes();
    }

    public Node cloneNode(boolean bln) {
        return delegateDocument.cloneNode(bln);
    }

    public void normalize() {
        delegateDocument.normalize();
    }

    public boolean isSupported(String string, String string1) {
        return delegateDocument.isSupported(string, string1);
    }

    public String getNamespaceURI() {
        return delegateDocument.getNamespaceURI();
    }

    public String getPrefix() {
        return delegateDocument.getPrefix();
    }

    public void setPrefix(String string) throws DOMException {
        delegateDocument.setPrefix(string);
    }

    public String getLocalName() {
        return delegateDocument.getLocalName();
    }

    public boolean hasAttributes() {
        return delegateDocument.hasAttributes();
    }

    public String getBaseURI() {
        return delegateDocument.getBaseURI();
    }

    public short compareDocumentPosition(Node node) throws DOMException {
        return delegateDocument.compareDocumentPosition(node);
    }

    public String getTextContent() throws DOMException {
        return delegateDocument.getTextContent();
    }

    public void setTextContent(String string) throws DOMException {
        delegateDocument.setTextContent(string);
    }

    public boolean isSameNode(Node node) {
        return delegateDocument.isSameNode(node);
    }

    public String lookupPrefix(String string) {
        return delegateDocument.lookupPrefix(string);
    }

    public boolean isDefaultNamespace(String string) {
        return delegateDocument.isDefaultNamespace(string);
    }

    public String lookupNamespaceURI(String string) {
        return delegateDocument.lookupNamespaceURI(string);
    }

    public boolean isEqualNode(Node node) {
        return delegateDocument.isEqualNode(node);
    }

    public Object getFeature(String string, String string1) {
        return delegateDocument.getFeature(string, string1);
    }

    public Object setUserData(String string, Object o, UserDataHandler udh) {
        return delegateDocument.setUserData(string, o, udh);
    }

    public Object getUserData(String string) {
        return delegateDocument.getUserData(string);
    }

}
